package com.jrfid.smartcabinet.demo.ui.cabinet_config.adapter

import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.BaseDraggableModule
import com.chad.library.adapter.base.module.DraggableModule

class SwipeDeleteModule(var baseQuickAdapter: BaseQuickAdapter<*, *>) : BaseDraggableModule(baseQuickAdapter) {

    override fun onItemSwiped(viewHolder: RecyclerView.ViewHolder) {
        val pos = getViewHolderPosition(viewHolder)
        if (pos > 0) {
            super.onItemSwiped(viewHolder)
            val size = baseQuickAdapter.data.size
            if (pos < size)
                baseQuickAdapter.notifyItemRangeChanged(pos, size - pos)
        } else {
            baseQuickAdapter.notifyItemChanged(pos)
        }
    }
}